@charset "UTF-8";

// Built-in modules
@use "sass:color";
@use "sass:list";
@use "sass:map";
@use "sass:math";
@use "sass:meta";
@use "sass:selector";
@use "sass:string";

// Settings and debugging
@use "mixkit/settings" as settings;
@use "list-to-string" as *;

/// Recursively convert map keys or values to a string.
///
/// @name map-to-string
///
/// @group mixkit/convert/utility
///
/// @param {map} $value
///   Map to convert.
///
/// @param {string} $string - [""]
///   String to append results to.
///
/// @param {boolean} $keys - [false]
///   Convert map keys to string instead of map values.
///
/// @return {string}
///
/// @require {function} list-to-string
///
/// @access public
///
/// @since 1.0.0

@function map-to-string($value, $string: "", $keys: false) {
  // Logic
  @for $i from 1 through list.length(map.keys($value)) {
    $key: list.nth(map.keys($value), $i);
    $char: map.get($value, $key);

    @if $keys == true {
      @return list-to-string(map.keys($value), $string);
    } @else if $keys == false {
      @if meta.type-of($char) == "list" {
        $string: list-to-string($char, $string);
      } @else if meta.type-of($char) == "map" {
        $string: $string + map-to-string($char, $string: "", $keys: $keys);
      } @else {
        $char: string.quote(string.unquote("#{$char}"));
        $string: string.insert($string, $char, $i);
      }
    }
  }
  @return $string;
}
